interface IUSerStore {
  token: string
  uInfo: {}
}

export const useUser = defineStore('user', {
  state: () => ({
    uInfo: {},
    token: '',
  }),
  actions: {
    // 写到上边middleware里用不了...
    async signIn(params: {}) {
      const router = useRouter()
      const token = 'TEST-TOKEN'
      const uInfo = { name: '用户' }
      Object.assign(this, { token, uInfo })
      router.push({ name: 'main' })
    },
    async signOut() {
      const router = useRouter()
      Object.assign(this, { token: '', uInfo: {} })
      router.push({ name: 'user-login' })
    },
  },
  persist: {
    key: 'YKXBC-USER',
  },
})
